package main

import (
	"context"
	"fmt"

	"gitee.com/cdsfish/skills/grpc/hello"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {

	// 1、 grpc客户端是自动生成好的

	//grpc.Dail负责和gRPC服务端建立连接
	// conn, err := grpc.Dial("127.0.0.1:1234", grpc.WithInsecure())
	conn, err := grpc.NewClient("127.0.0.1:1234", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		panic(err)
	}

	defer conn.Close()

	//2、基于conn初始化一个 客户端对象
	c := hello.NewHelloServiceClient(conn)
	resp, err := c.Hello(context.Background(), &hello.HelloRequest{Name: "cds"})

	if err != nil {
		panic(err)
	}
	fmt.Println(resp)
}
